/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-07-07
 * Time: 23:03
 */
//https://leetcode.cn/problems/same-tree/
//给你两棵二叉树的根节点 p 和 q ，编写一个函数来检验这两棵树是否相同。
//如果两个树在结构上相同，并且节点具有相同的值，则认为它们是相同的。
class TreeNode {
    int val;
    TreeNode left;
    TreeNode right;
    TreeNode() {}
    TreeNode(int val) { this.val = val; }
    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }
}
public class Test {
     public static boolean isSameTree(TreeNode p, TreeNode q) {
        if(p==null&&q==null){
            return true;
        }
        if(p==null||q==null){
            return false;
        }
        if(p.val==q.val){
            return isSameTree(p.left,q.left)&&isSameTree(p.right,q.right);
        }
        else{
            return false;
        }
    }

    public static void main(String[] args) {
        TreeNode A1=new TreeNode(1);
        TreeNode A2=new TreeNode(2);
        TreeNode A3=new TreeNode(3);
        TreeNode A4=new TreeNode(4);
        TreeNode A5=new TreeNode(5);
        TreeNode A6=new TreeNode(6);
        TreeNode A7=new TreeNode(7);
        A1.left=A2;A1.right=A3;
        A2.left=A4;A2.right=A5;
        A3.left=A6;A3.right=A7;
        TreeNode B1=new TreeNode(1);
        TreeNode B2=new TreeNode(2);
        TreeNode B3=new TreeNode(3);
        TreeNode B4=new TreeNode(4);
        TreeNode B5=new TreeNode(5);
        TreeNode B6=new TreeNode(6);
        TreeNode B7=new TreeNode(7);
        B1.left=B2;B1.right=B3;
        B2.left=B4;B2.right=B5;
        B3.left=B6;B3.right=B7;
        System.out.println(isSameTree(A1,B1));
    }
}
